package com.ys.otms.controller;

import com.ys.otms.services.IYLClassificationServices;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2018/10/12.
 */
@Controller
@RequestMapping("/ylclassifcation")
public class YLClassificationController {
    private static Logger logger = LoggerFactory.getLogger(YLClassificationController.class);
    @Autowired
    private IYLClassificationServices iylClassificationServices;

    /**
     * 新增运力分类
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/insertYLClassificationQuery")
    @ResponseBody
    public JSONObject insertYLClassificationQuery(HttpServletRequest request) throws Exception{
        logger.info("YLClassificationController insertYLClassificationQuery start");
        JSONObject jsonClassification = new JSONObject();
        try {
            jsonClassification = iylClassificationServices.insertYLClassificationQuery(request);
        } catch (Exception e) {
            logger.error("YLClassificationController insertYLClassificationQuery Exception",e);
            jsonClassification.put("SUCCESS",false);
            jsonClassification.put("MSG","新增数据失败！");
        }
        return jsonClassification;
    }


    /**
     * 查询运力分类
     * @param request
     * @return
     */
    @RequestMapping("/selectYLClassification")
    @ResponseBody
    public JSONObject selectYLClassification(HttpServletRequest request) throws Exception {
        logger.info("YLClassificationController selectYLClassification start");
        JSONObject jsonClassificationShips = new JSONObject();
        try {
            jsonClassificationShips = iylClassificationServices.selectYLClassification(request);
        } catch (Exception e) {
            logger.error("YLClassificationController selectYLClassification error", e);
            jsonClassificationShips.put("SUCCESS",false);
            jsonClassificationShips.put("MSG","查询数据失败！");
        }
        return jsonClassificationShips;
    }

    /**
     * 根据运力分类查询船舶
     * @param request
     * @return
     */
    @RequestMapping("/selectShipsByYLClassification")
    @ResponseBody
    public JSONObject selectShipsByYLClassification(HttpServletRequest request) throws Exception {
        logger.info("YLClassificationController selectShipsByYLClassification start");
        JSONObject jsonClassificationShips = new JSONObject();
        try {
            jsonClassificationShips = iylClassificationServices.selectShipsByYLClassification(request);
        } catch (Exception e) {
            logger.error("YLClassificationController selectShipsByYLClassification error", e);
            jsonClassificationShips.put("SUCCESS",false);
            jsonClassificationShips.put("MSG","查询数据失败！");
        }
        return jsonClassificationShips;
    }

    /**
     * 删除运力分类
     * @param request
     * @return
     */
    @RequestMapping("/deleteYLClassification")
    @ResponseBody
    public JSONObject deleteYLClassification(HttpServletRequest request) throws Exception {
        logger.info("YLClassificationController deleteYLClassification start");
        JSONObject jsonClassificationShips = new JSONObject();
        try {
            jsonClassificationShips = iylClassificationServices.deleteYLClassification(request);
        } catch (Exception e) {
            logger.error("YLClassificationController deleteYLClassification error", e);
            jsonClassificationShips.put("SUCCESS",false);
            jsonClassificationShips.put("MSG","删除失败！");
        }
        return jsonClassificationShips;
    }


    /**
     * 查询没有添加到分类中的船舶
     * @param request
     * @return
     */
    @RequestMapping("/selectNotClassificationShips")
    @ResponseBody
    public JSONObject selectNotClassificationShips(HttpServletRequest request) {
        logger.info("YLClassificationController selectNotClassificationShips start");
        JSONObject jsonClassificationShips = new JSONObject();
        try {
            jsonClassificationShips = iylClassificationServices.selectNotClassificationShips(request);
        } catch (Exception e) {
            logger.error("YLClassificationController selectNotClassificationShips error", e);
            jsonClassificationShips.put("SUCCESS",false);
            jsonClassificationShips.put("MSG","查询数据失败！");
        }
        return jsonClassificationShips;
    }

}
